<?php
final class App_Admin_Service_DbStructure extends Main_Service_DbStructureAbstract
{
	/**
	 * @var App_Admin_Service_DbStructure
	 */
	private static $_instance;
		
	/**
	 * @var App_Admin_Service_DbStructure
	 */
	public static function getInstance() 
	{
		if (null === self::$_instance) {
            self::$_instance = new self();
        }
        return self::$_instance;
	}
	
	/**
	 * @param string $driver
	 * @param string|null $driverType
	 * @return string
	 */	
	public function getInstallSql($driver, $driverType = null)
	{
		// --- mysql --- {{
		if ($driver == 'mysql') 
		{
			// --- mysql myisam --- {{
			if ($driverType = 'myisam') 
			{
				$sql = <<<SQL
drop table if exists lang;
create table lang
(
   id                   tinyint unsigned not null auto_increment,
   abbr                 varchar(10) not null,
   primary key (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

drop table if exists lang_i18n;
create table lang_i18n
(
   id                   tinyint unsigned not null auto_increment,
   lang_id              tinyint unsigned not null,
   name                 varchar(100) not null,
   primary key (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

drop table if exists plugin;
create table plugin
(
   id                   smallint unsigned not null auto_increment,
   name                 varchar(255) not null,
   f_active             tinyint(1) not null,
   primary key (id)
);

drop table if exists plugin_i18n;
create table plugin_i18n
(
   id                   smallint unsigned not null auto_increment,
   title                varchar(255) not null,
   description          varchar(1000) not null,
   lang_id              tinyint unsigned not null,
   plugin_id            smallint unsigned not null,
   primary key (id)
);

SQL;
			}
			// --- mysql myisam --- }}
		}
		// --- mysql --- }}
	
		return $sql;		
	}

	/**
	 * @return void
	 */
	public function setDefaultData()
	{
		$langAbbr = Zend_Registry::getInstance()->langAbbr;
		$langName = Zend_Registry::getInstance()->langName;
		
		$this->db->insert('lang', array("abbr"=>"'ru'"));
		
		$id = $this->db->lastInsertId('lang');
		
		Zend_Registry::getInstance()->langId = $id;
		
		$this->db->insert('lang_i18n', array("lang_id"	=> $id,
										     "name"		=> "'{$langName}'"));
	}
}
?>